package com.bishe.demo.controller;


import com.bishe.demo.pojo.Commodity;
import com.bishe.demo.pojo.Sale;
import com.bishe.demo.pojo.vo.Status;
import com.bishe.demo.service.CommodityService;
import com.bishe.demo.service.LoginService;
import com.bishe.demo.service.SaleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {

    @Autowired
    LoginService loginService;

    @Autowired
    SaleService saleService;

    @Autowired
    CommodityService commodityService;

    @RequestMapping("/")
    public String login(HttpSession httpSession){

        return "login";
    }

    //接收密码
    @RequestMapping( "receivePwd")
    public String jieShouPwd(String name, String pwd, HttpSession httpSession, HttpServletRequest request){
        System.out.println("我是名字"+name);
        System.out.println(pwd);
        Status status = loginService.jiaoyanPwd(name,pwd);
        List<Sale> list = saleService.selectSale();

        List<Commodity> list1 = commodityService.selectAllCom();
        httpSession.setAttribute("deleteList",list1);

        httpSession.setAttribute("listSale",list);

        httpSession.setAttribute("loginmsg",status.getMsg());

        if (!status.isCode()){
            return "login";
        }else {
            httpSession.setAttribute("username",name);
            request.getSession().setAttribute("whatName",name);
            return "index";
        }

    }
}
